﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class PrintChargeModeWebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string ifrosc = "不打印";
                Data_Binding(ifrosc);
            }
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string ifrosc = "打印";
            Data_Binding( ifrosc);
        }

        protected void btnSearch_Click1(object sender, EventArgs e)
        {
            string ifrosc = "不打印";
            Data_Binding(ifrosc);
        }




        private void Data_Binding( string ifrosc)
        {
            string strReportName = Server.UrlDecode(Request.QueryString["AlarmEventType"]); //System.Web.HttpContext.Current.Session["ReportName"].ToString();
            string taskCode = Request.QueryString["TaskCode"];
            int patientOrder = Convert.ToInt32(Request.QueryString["PatientOrder"]);
            //ifCharge为 0 ，一般病历单打印，ifCharge为1 ，病历收费打印
            //int ifCharge = Convert.ToInt32(Request.QueryString["IfCharge"]);

            string submitLogo = Request.QueryString["SubmitLogo"];//20151214提交标志
            if (submitLogo == "true" || submitLogo == null)
            {
                ReportViewer1.ShowToolBar = true;//显示功能列表
            }
            else
                ReportViewer1.ShowToolBar = false;//隐藏功能列表

            string IFHasPower = "无";
            //List<int> roles = UserOperateContext.Current.Session_UsrRole; //获取登录人角色
            //string configRole = System.Configuration.ConfigurationManager.AppSettings["PRAuditCPR"]; //配置文件中取出能有审核心肺复苏的角色编码
            //string[] tcr = configRole.Split(',');

            M_PatientChargeDAL dalzz = new M_PatientChargeDAL();
            DataTable dtroscif = dalzz.getPatientROSCPrint(taskCode, patientOrder);//通过ROSC的车到前CPR的长度判断是否填写了ROSC
            //string tempcpr = dtroscif.Rows[0][3].ToString();
            string tempcpr = dtroscif.ToString();　//add2021-10-15 plq 医保上线移植
         
            //从前台传过来的参数显示是否需要打印rosc,不需要的话就是“否”


            if (ifrosc == "打印" && tempcpr.Length > 0) { IFHasPower = "有"; } //判断只有当角色有查看ROSC权限，并且ROSC有填写，同时满足才可以查看

                switch (strReportName)
                {
                    case "救治":
                        this.ReportViewer1.LocalReport.DataSources.Clear();
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForJiJiuOrZhuanyuan.rdlc");
                        Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("IFHasPower", IFHasPower);//传参判断是否有查看权限
                        this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { ed });
                        M_PatientChargeDAL dal = new M_PatientChargeDAL();
                        DataTable dtrosc1 = dal.getPatientROSCPrint(taskCode, patientOrder);//新增ROSC的打印
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientROSC", dtrosc1));
                        DataTable dt = dal.getPatientChargePrintCar(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPCar", dt));
                        DataTable dt1 = dal.getPatientChargePrintOther(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPOther", dt1));
                        break;
                    case "一般转院":
                    case "急救转院":
                        this.ReportViewer1.LocalReport.DataSources.Clear();
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForJiJiuOrZhuanyuan.rdlc");
                        Microsoft.Reporting.WebForms.ReportParameter ed1 = new Microsoft.Reporting.WebForms.ReportParameter("IFHasPower", IFHasPower);
                        this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { ed1 });
                        M_PatientChargeDAL dal1 = new M_PatientChargeDAL();
                        DataTable dtrosc2 = dal1.getPatientROSCPrint(taskCode, patientOrder);//新增ROSC的打印
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientROSC", dtrosc2));
                        DataTable dt2 = dal1.getPatientChargePrintCar(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPCar", dt2));
                        DataTable dt3 = dal1.getPatientChargePrintOther(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPOther", dt3));
                        break;

                    case "回家":
                        this.ReportViewer1.LocalReport.DataSources.Clear();
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForHuiJia.rdlc");
                        Microsoft.Reporting.WebForms.ReportParameter ed2 = new Microsoft.Reporting.WebForms.ReportParameter("IFHasPower", IFHasPower);
                        this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { ed2 });
                        M_PatientChargeDAL dal2 = new M_PatientChargeDAL();
                        DataTable dtrosc3 = dal2.getPatientROSCPrint(taskCode, patientOrder);//新增ROSC的打印
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientROSC", dtrosc3));
                        DataTable dt4 = dal2.getPatientChargePrintCar(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForHJCar", dt4));
                        DataTable dt5 = dal2.getPatientChargePrintZhiLiao(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForHJZhiLiao", dt5));
                        break;


                    case "其他":
                        this.ReportViewer1.LocalReport.DataSources.Clear();
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForQuNuanXiang.rdlc");
                        M_PatientChargeDAL dal3 = new M_PatientChargeDAL();
                        DataTable dt6 = dal3.getPatientChargePrintCar(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForChargePrintKongChe", dt6));
                        break;

                    case "空车":
                        this.ReportViewer1.LocalReport.DataSources.Clear();
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForKongChe.rdlc");
                        M_PatientChargeDAL dal4 = new M_PatientChargeDAL();
                        DataTable dt7 = dal4.getPatientChargePrintCar(taskCode, patientOrder);
                        this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForChargePrintKongChe1", dt7));
                        break;
                    default:
                        break;
                }
                this.ReportViewer1.LocalReport.Refresh();
            }
    }
}